"""
实现参数输入和搜索模式选择
"""

import os

from base import *


def valid_input(get_tip="", wrong_tip="", is_valid=lambda x: x):
    while True:
        input_ = input(get_tip)
        if is_valid(input_):
            return rf"{input_}"
        else:
            print(wrong_tip)


class LocalMiner:
    """

    """

    def __init__(self, root, key, type_):
        self.root = root
        self.key = key
        self.type_ = int(type_)

    def start(self):
        if self.type_ in [0, 2]:
            k = NameSearch(self.root, self.key)
            k.run()
        if self.type_ in [1, 2]:
            k = ContentSearch(self.root, self.key)
            k.run()


if __name__ == '__main__':
    root = valid_input("Please input the root directory: ", "Valid dir path!", os.path.exists)
    key = valid_input("Please input the keyword: ", "Valid keyword!")
    type_ = valid_input("Please input the search method:\n[0] Search path  [1] Search file content  [2] Both\n",
                        "Valid method!", lambda x: x in ['0', '1', '2'])
    l = LocalMiner(root, key, type_)
    l.start()
"""
D:\Python\ModernProgramming\Async
李青云
"""
